package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.product.CategoryBrandVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "商品分类品牌管理模块")
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Resource
    CategoryBrandService categoryBrandService;
    @Operation(summary = "根据三级分类id查询分类下的品牌列表")
    @GetMapping("listBrandsByCategoryId/{categoryId}")
    public Result<List<Brand>> listBrandsByCategoryId(@PathVariable("categoryId")Long categoryId){
        List<Brand> brands = categoryBrandService.listBrandsByCategoryId(categoryId);
        return Result.ok(brands);
    }

    @Operation(summary = "更新分类品牌")
    @PutMapping
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.ok(null);
    }
    @Operation(summary = "新增分类品牌")
    @PostMapping
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.ok(null);
    }
    @Operation(summary = "根据id删除分类品牌")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        categoryBrandService.deleteById(id);
        return Result.ok(null);
    }


    @Operation(summary = "条件查询分类品牌分页数据")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result<PageInfo<CategoryBrandVo>> page(@PathVariable("pageNum")Integer pageNum,
                                                  @PathVariable("pageSize")Integer pageSize,
                                                  CategoryBrandDto categoryBrandDto){
        PageInfo<CategoryBrandVo> pageInfo = categoryBrandService.page(pageNum , pageSize ,categoryBrandDto);

        return Result.ok(pageInfo);
    }
    /*
        条件查询分类品牌的分页数据：
            1、前端提交的参数： 定义Dto接收前端参数
                品牌id+ 最后一级的分类id
                pageNum+pageSize
            2、查询涉及的表：根据前端展示的数据
                分类名称、分类id： category
                品牌： 名称、图标、品牌id  brand
                创建时间+删除更新使用的id： category_brand

                服务器组件：
                    Controller、Service、Mapper
                        CategoryMapper、BrandMapper
                        新建：CategoryBrandMapper
                        新建：CategoryBrand

            3、返回数据：涉及多张表的字段
                一般自定义Vo类封装数据:


     */

}
